package com.intel.two.service.older.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.intel.two.common.older.LayuiPageVo;
import com.intel.two.mapper.older.SuiteMapper;
import com.intel.two.pojo.older.Suite;
import com.intel.two.service.older.SuiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service("suiteService")
public class SuiteServiceImpl implements SuiteService {

    @Autowired
    private SuiteMapper suiteMapper;
    @Override
    public LayuiPageVo<Suite> suitePageData(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page")+"");
        Integer limit = Integer.parseInt(params.get("limit")+"");

        PageHelper.startPage(page,limit);
        List<Suite> suites =  suiteMapper.selectByParams(params);

        PageInfo<Suite> suitePageInfo = new PageInfo<>(suites);
        LayuiPageVo<Suite> suiteLayuiPageVo = new LayuiPageVo<>();
        suiteLayuiPageVo.setCode(0);
        suiteLayuiPageVo.setMsg("学生分页列表数据");
        suiteLayuiPageVo.setCount(suitePageInfo.getTotal());  // 总记录数
        suiteLayuiPageVo.setData(suitePageInfo.getList());  // 分页列表数据
        return suiteLayuiPageVo;
    }

    @Override
    public int addSuite(Suite suite) {
        int result = suiteMapper.addSuite(suite);
        return result;

    }

    @Override
    public int deleteById(Integer id) {
        int result = suiteMapper.deleteById(id);
        return result;
    }

    @Override
    public int deleteAll(Map<String, Object> map) {
        String str = (String) map.get("oldman_roomid");
        String[] strs = str.split("-");
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < strs.length; i++) {
            list.add(Integer.parseInt(strs[i]));
            System.out.println(strs[i]);
        }
        return suiteMapper.deleteAll(list);
    }
    @Override
    public int udateSuite(Suite suite) {
        int result = suiteMapper.updateSuite(suite);
        return result;
    }
}
